/**
 * Created by cheny on 2016/7/28.
 */
(function(){
    'use strict';
    app.factory('requisitionAuditService',['$http','$q',function($http,$q){
        $http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
        var factory={
            getRequisitionDetail:getRequisitionDetail,
            getRequisitionList:getRequisitionList,
            audit:audit
        };
        return factory;

        function getRequisitionDetail(pkId){

            var deferred=$q.defer();
            var promise=$http.get("/user/getrequisitiondetail?pkId="+pkId);
            promise.then(
                function(success){
                    deferred.resolve(success.data);
                },
                function(error){
                    console.log(error);
                    deferred.reject(error);
                });
            return promise;
        }
        function getRequisitionList(queryCondition){
            var deferred=$q.defer();
            var promise=$http.post("/user/getrequisitionauditlist",$.param(queryCondition));
            promise.then(
                function(success){
                    deferred.resolve(success.data);
                },
                function(error){
                    console.log(error);
                    deferred.reject(error);
                });
            return promise;
        }

        function audit(pkId,isPassed,message){
            var deferred=$q.defer();
            var condition={
                pkId:pkId,
                isPassed:isPassed,
                message:message
            }
            var promise=$http.post("/user/requisitionaudit", $.param(condition));
            promise.then(
                function(success){
                    deferred.resolve(success.data);
                },
                function(error){
                    console.log(error);
                    deferred.reject(error);
                });
            return promise;
        }
    }]);
})();
